namespace Xmef.Serializer
{
    using System;
    using System.Xml;
    using System.Xml.Serialization;
    using Xmef.Interfaces;
    using Xmef.Library;
    using Xmef.Serializer.Internal;

    [Serializable]
    public abstract class XmlTypeSettings : PluginIdentity, IXmlRuntimeSerializerInternal, IXmlRuntimeSerializer, IXmlTypeFormatterInternal, IXmlTypeFormatter
    {
        [NonSerialized]
        private readonly XmlReaderSettings _readerSettings = new XmlReaderSettings();
        [NonSerialized]
        private Type _type;
        [NonSerialized]
        private readonly XmlWriterSettings _writerSettings = new XmlWriterSettings();

        protected XmlTypeSettings(Type type)
        {
            this._type = type;
            this._readerSettings.CloseInput = true;
            this._readerSettings.IgnoreComments = true;
            this._readerSettings.IgnoreWhitespace = true;
            this._writerSettings.CloseOutput = true;
            this._writerSettings.Indent = true;
        }

        internal abstract IXmlFormatAttributesInternal InternalAttributes { get; }

        internal abstract XmlSerializer InternalSerializer { get; }

        public Type RuntimeType
        {
            get
            {
                return this._type;
            }
        }

        public IXmlRuntimeSerializer Serializer
        {
            get
            {
                return this;
            }
        }

        IXmlFormatAttributesInternal IXmlRuntimeSerializerInternal.InternalAttributes
        {
            get
            {
                return this.InternalAttributes;
            }
        }

        XmlReaderSettings IXmlRuntimeSerializerInternal.ReaderSettings
        {
            get
            {
                return this._readerSettings;
            }
        }

        XmlSerializer IXmlRuntimeSerializerInternal.RuntimeSerializer
        {
            get
            {
                return this.InternalSerializer;
            }
        }

        XmlWriterSettings IXmlRuntimeSerializerInternal.WriterSettings
        {
            get
            {
                return this._writerSettings;
            }
        }

        IXmlRuntimeSerializerInternal IXmlTypeFormatterInternal.InternalSerializer
        {
            get
            {
                return this;
            }
        }

        protected XmlReaderSettings XmlReaderSettings
        {
            get
            {
                return this._readerSettings;
            }
        }

        protected XmlWriterSettings XmlWriterSettings
        {
            get
            {
                return this._writerSettings;
            }
        }
    }
}

